<div class="row">
<?php 
	if(empty($model->fids)) {
		$model->area_id = 0;
		$model->name = '';
		$model->fids = '-';
		$model->pid = '';
		$model->recommend_id = 2;
        //echo $model->fids;exit;
	}
?>
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'area-_form-form',
    'enableAjaxValidation'=>true,
    'enableClientValidation'=>true,
    'clientOptions'=>array(  
        'validateOnSubmit'=>true,  
     ),
)); ?>

<table class="table table-bordered table-hover definewidth">
    <tbody>
        <tr>
            <td width="10%" class="tableleft">
                区域：
            </td>
            <td>
                <?php echo $form->hiddenField($model ,'pid' ,array('id'=>'pid')); ?>          	
                <input <?php echo $model->pid==-1?'checked':''?> onclick="setParentId()" type="checkbox" id="pids"/>自治区、直辖市、特别行政区
            </td>
            <script type="text/javascript">
        	function setParentId() {
            	if($('#pids').attr('checked')){
            		$('#pid').val(-1);
                	$('#select_pid').attr('disabled', true);
                } else {
                	$('#select_pid').attr('disabled', false);
                	$('#pid').val($('#select_pid').val());
            	}
        	}

        	function setRecommendId() {
            	$('#recommend_id').val($('#rid').attr('checked')?1:0);
        	}

        	function setSelectPid() {
        		$('#pid').val($('#select_pid').val());
        	}

        	$(document).ready(function() {
        		setParentId();
        	})
        </script>            
	    </tr>
        <tr>
            <td width="10%" class="tableleft">
                <?php echo $form->labelEx($model,'recommend_id'); ?>
            </td>
            <td>
                <?php echo $form->radioButtonList($model,'recommend_id',Yii::app()->dict->get('area' ,'recommend_id') ,array('separator'=>'&nbsp;')); ?>
                <?php echo $form->error($model,'recommend_id'); ?>
            </td>            
	    </tr>
        <tr>
            <td width="10%" class="tableleft">
                区域名称：
            </td>
            <td>
                <?php echo $form->textField($model,'name',array('id'=>'areaname')); ?>
                <?php echo $form->error($model,'name'); ?>
            </td>            
	    </tr>
        <tr>
            <td width="10%" class="tableleft">
                上级区域：
            </td>
            <td>
                <div class="box">
        			<select id="select_pid" onchange="setSelectPid()">
        				<option value="0">根级区域</option>
        				<?php
        					foreach($list as $row=>$value) {
        						$fids=explode(',', $value->fids);
        						$fids=count($fids);
        						while ($fids-->1) $value->name = $fids==1 ? '|'.$value->name:'-'.$value->name;
        				?>
        				<option <?php if(strpos($value->fids, $model->fids)>-1) echo 'disabled=true'?> value="<?php echo $value->area_id ?>" <?php if($model->pid==$value->area_id) echo 'selected'?>><?php echo $value->name ?></option>
        				<?php } ?>
        			</select>      
        		</div>    
            </td>            
	    </tr>
        <tr>
            <td width="10%" class="tableleft"></td>
            <td>
                <?php echo $form->hiddenField($model ,'area_id'); ?>
                <?php echo CHtml::submitButton('保存',array('class'=>'button button-primary'));?>
                <?php echo CHtml::link('返回列表',$this->createUrl('area/index'),array('class'=>'button button-success'));?>
            </td>            
        </tr>
    </tbody>
</table>
<?php $this->endWidget(); ?>
</div>